//package com.lt.test.consumer.controller;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.lt.test.api.CgtCustService;
//import com.lt.test.api.SPLOrderService;
//import com.lt.test.common.constant.HttpRequestConstant;
//import com.lt.test.common.exception.CustomException;
//import com.lt.test.common.util.HttpClientUtil;
//import com.lt.test.entity.DTO.OrderPayInfoDTO;
//import com.lt.test.entity.DTO.PageDTO;
//import com.lt.test.entity.DTO.ResponseDTO;
//import com.lt.test.entity.DTO.SPLOrderDTO;
//import com.lt.test.entity.QueryModel.MapQueryModel;
//import net.sf.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * Created by zhengchuan on 2017/3/14.
// */
//@Controller
//@RequestMapping("/sys/clouderp")
//public class SPLOrderContriller {
//    private static final Logger logger = LoggerFactory.getLogger(ClouderpController.class);
//    @Reference(version = "1.0.0")
//    private SPLOrderService sPLOrderService;
//    @Reference(version = "1.0.0")
//    private CgtCustService cgtCustService;
//
//    /**
//     * 分页查询烟草客户订单信息
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getSPLOrderInfo")
//    public
//    @ResponseBody
//    PageDTO<SPLOrderDTO> getSPLOrderInfo(HttpServletRequest request, HttpServletResponse response) {
//        Integer page = Integer.valueOf(request.getParameter("page"));
//        Integer pageSize = Integer.valueOf(request.getParameter("rows"));
//        String sortedKey = request.getParameter("sidx");
//        String sortedValue = request.getParameter("sord");
//        String filters = request.getParameter("filters");
//        PageDTO<SPLOrderDTO> result = null;
//        try {
//            result = sPLOrderService.findSPLOrderByPage(page, pageSize, sortedKey, sortedValue, filters);
//        } catch (CustomException e) {
//            logger.error("获取烟草客户订单失败");
//            e.printStackTrace();
//            result = new PageDTO<>();
//        }
//        return result;
//    }
//
//    /**
//     * 分页查询烟草客户订单信息 --手机版
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getSPLOrderInfoM")
//    public
//    @ResponseBody
//    ResponseDTO getSPLOrderInfoM(HttpServletRequest request, HttpServletResponse response, MapQueryModel params) {
//
//        ResponseDTO responseDTO = new ResponseDTO();
//        responseDTO.setData(sPLOrderService.findSPLOrderByPage(params.getStringMap()));
//        responseDTO.setSuccess(true);
//        return responseDTO;
//    }
//
//    /**
//     * 获取烟草客户订单支付相关信息
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getPayInfo")
//    public
//    @ResponseBody
//    ResponseDTO getPayInfo(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String orderId = request.getParameter("orderId");
//        try {
//            List<OrderPayInfoDTO> result = sPLOrderService.getPayInfo(orderId);
//            responseDTO.setCode("200");
//            responseDTO.setSuccess(true);
//            responseDTO.setMessage("获取支付详情成功");
//            responseDTO.setData(result);
//        } catch (CustomException e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage(e.getMessage());
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("服务器异常");
//        }
//        return responseDTO;
//
//    }
//
//    /**
//     * 获取订单交易信息（去银联查询）
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getTransStatusInfo")
//    public
//    @ResponseBody
//    ResponseDTO getTransStatusInfo(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String custCode = request.getParameter("custCode");
//        String merchantCode = request.getParameter("merchantCode");
//        String payOrderNo = request.getParameter("payOrderNo");
//        String transDateStr = request.getParameter("transDateStr");
//        final String URL = "http://10.95.0.233:23912/clouderp-cgt-order-rest/api/cgt/order/queryTranStatus";
//        Map<String, String> params = new HashMap<>(5, 1.0F);
//        params.put("custCode", custCode);
//        params.put("merchantCode", merchantCode);
//        params.put("payOrderNo", payOrderNo);
//        params.put("txnTime", transDateStr);
//        params.put("debugSkipSignValidate", "1");
//
//        try {
//            String responseResult = HttpClientUtil.sendPostRequest(URL, params, null, null);
//            JSONObject jsonObject = JSONObject.fromObject(responseResult);
//            if (jsonObject.size() == 0 || !"000".equals(jsonObject.get("code"))) {
//                responseDTO.setMessage("获取交易状态失败");
//            } else {
//                responseDTO.setCode("200");
//                responseDTO.setSuccess(true);
//                responseDTO.setMessage("获取交易状态成功");
//                responseDTO.setData(jsonObject.get("data"));
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("服务器异常");
//        }
//        return responseDTO;
//
//    }
//
//    /**
//     * 通知客户交易情况
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/notificationUser")
//    public
//    @ResponseBody
//    ResponseDTO notificationUser(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String tradeFlag = request.getParameter("tradeFlag");
//        String isSendCloudlingMsg = request.getParameter("isSendCloudlingMsg");
//        String custCode = request.getParameter("custCode");
//        String orderId = request.getParameter("orderId");
//        String userPhone = request.getParameter("userPhone");
//        String payOrderNo = request.getParameter("payOrderNo");
//        String orderAmount = request.getParameter("orderAmount");
//
//        final String URL = HttpRequestConstant.REST_SERVER_URL+"/clouderp-cgt-order-rest/api/cgt/order/notifyOrder";
//        Map<String, String> params = new HashMap<>(6, 1.0F);
//        params.put("custCode", custCode);
//        params.put("orderNo", orderId);
//        params.put("payOrderNo", payOrderNo);
//        params.put("orderAmount", orderAmount);
//        params.put("tradeFlag", tradeFlag);
//        params.put("debugSkipSignValidate", "1");
//
//        responseDTO.setMessage("");
//        try {
//            if ("1".equals(isSendCloudlingMsg)) {
//                String price = null;
//                if (orderAmount.length()==1){
//                    price = "0.0"+orderAmount;
//                }else if (orderAmount.length()==2){
//                    price = "0."+orderAmount;
//                }else {
//                    String preString = orderAmount.substring(0,orderAmount.length()-2);
//                    String brfString = orderAmount.substring(orderAmount.length()-2);
//                    price = preString+"."+brfString;
//                }
//                String content = "尊敬的"+custCode+"，您的订单"+orderId+"金额"+price+"支付失败";
//                if ("1".equals(tradeFlag)){
//                    content = "尊敬的"+custCode+"，您的订单"+orderId+"金额"+price+"支付成功";
//                }
//                cgtCustService.sendCloudingMessage(userPhone, content);
//                responseDTO.setMessage("小云发送成功");
//            }
//
//            String responseResult = HttpClientUtil.sendPostRequest(URL, params, null, null);
//            JSONObject jsonObject = JSONObject.fromObject(responseResult);
//            if (jsonObject.size() == 0 || !"000".equals(jsonObject.get("code"))) {
//                responseDTO.setMessage(responseDTO.getMessage() + " 通知失败");
//
//
//            } else {
//
//                responseDTO.setCode("200");
//                responseDTO.setSuccess(true);
//                responseDTO.setMessage(responseDTO.getMessage() + " 通知成功");
//                responseDTO.setData(jsonObject.get("data"));
//            }
//        } catch (CustomException e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("小云消息和通知都失败");
//        }
//        catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("未知错误");
//        }
//        return responseDTO;
//
//    }
//
//
//
//}
